package cn.kiwipeach.blog.service.impl;

import cn.kiwipeach.blog.domain.AccessTokenVO;
import cn.kiwipeach.blog.exception.BlogException;
import cn.kiwipeach.blog.service.IAccessTokenService;
import lombok.extern.slf4j.Slf4j;
import open.kiwipeach.autoconfigure.shiro.token.AccessToken;
import open.kiwipeach.autoconfigure.web.utils.JwtTokenUtil;
import org.springframework.stereotype.Service;

/**
 * 描述：用户访问token服务实现类
 *
 * @author kiwipeach
 * @since 2.0
 */
@Service
@Slf4j
public class AccessTokenServiceImpl implements IAccessTokenService {


    @Override
    public AccessTokenVO cacheStoreToken(AccessToken accessToken) {
        log.warn("cacheStoreToken中的类加载器:{}", getClass().getClassLoader());
        return new AccessTokenVO(accessToken.getToken(), accessToken.getExpiresTime(), accessToken.getRefreshToken());
    }

    @Override
    public AccessTokenVO getAccessToken(String userId, String refreshToken) {
        throw new BlogException("-ACCESS-TOKEN-01", "token已失效");
    }

    @Override
    public AccessTokenVO refreshToken(String refreshToken, AccessToken newAccessToken) {
        return JwtTokenUtil.signToken(newAccessToken);
    }

    @Override
    public Boolean removeToken(AccessToken accessToken) {
        return true;
    }

}
